<style>
    label{ display:inline-block;width: 10%}
</style>
<div class="container-fluid" style="padding: 20px 10px 0px 10px">

    <div class="row-fluid">

        <div class="well">

            <ul class="nav nav-tabs">

                <li class="active"><b>还货入库</b></li>

            </ul>

            <div id="myTabContent" class="tab-content">

                <div class="tab-pane active in" id="home">

                    <form id="formid" action="/take/return_storage" method="post" style="width: 100%;text-align: left">
                        <input type="hidden" name="usedetail_id" value="<?=I('get.id')?>">
                        <input type="hidden" name="take_orderid" value="<?=I('get.order_id')?>">
                        <input type="hidden" name="drug_id" value="<?=$detail['drug_id']?>">
                        <input type="hidden" name="warehouse" value="<?=$detail['warehouse']?>">
                        <input type="hidden" name="last_num" value="<?=$detail['last_num']?>">
                        <input type="hidden" name="dosubmit" value="1">
                        <p>
                            <span style="color: red">*</span><label>还回数量 : </label>
                            <input type="text" name="return_num" value="">
                            <span style="color: red;padding-left: 18px;">*</span><label>还入仓库 : </label>
                            <select name="return_storage">
                                <?php if($storage){foreach($storage as $k=>$v){?>
                                <option value="<?=$k?>" <?=$detail['warehouse'] == $k?'selected':'' ?>><?=$v?></option>
                                <?php }}?>
                            </select>

                        </p>
                        <p><label>还货人 : </label>

                            <input type="text" name="return_user" value="">

                            <label style="padding-left: 28px;">还货日期 : </label>

                            <input name="return_date" readonly placeholder="还货日期" class="input input-medium"
                                   onclick='WdatePicker({dateFmt:"yyyy-MM-dd"})' type="text" value=""></p>
                        <p>
                            <label>备注 : </label>
                            <textarea style="display:inline; width: 529px; height: 50px;" name="remark"><?=$drugList['remark']?></textarea>

                        </p>


                        <div class="btn-toolbar">
                            <div class="btn-group" style="margin:30px 0 10px 280px;">
                                <input type="submit" name="" value="保存" class="btn btn-primary">
                            </div>
                        </div>
                    </form>

                </div>

            </div>

        </div>

    </div>

    <script>

        $(function(){

            $('#btn-save').click(function(){
                $('#formid').submit();
            });

            $('#realuse_num').on('change',function() {
                var real_num = $(this).val();
                var take_num = $('#take_num').val();
                if(real_num < 0 || take_num < 0){
                    alert('实际用量和领出量必须为正整数');
                }else{
                    var last_num = parseInt(take_num)-parseInt(real_num);
                    $('input[name=last_num]').val(last_num);
                }
            });

            $('#sel_house').on('change',function() {
                var val = $(this).val();
                $.ajax({
                    url: '/take/onehouse_drug',
                    type: 'POST',
                    dataType: 'json',
                    data: {sel_house: val,type:'药品'},
                })
                    .done(function(data) {
                        if(data.code == '0'){
                            $('#drug_id').empty();
                            $('#drug_id').append('<option value="0">请选择</option>');
                            for(item in data.data){
                                $('#drug_id').append('<option value="'+item+'">'+data.data[item]+'</option>');
                            }
                        }else{
                            alert(data.msg);
                        }
                    })
            });

            $('#drug_id').on('change',function(){
                var val = $(this).val();
                $.ajax({
                    url: '/drug/getDrugInfo',
                    type: 'POST',
                    dataType: 'json',
                    data: {id: val},
                })
                    .done(function(data) {
                        if(data.code == '0'){
                            $('input[name=type]').val(data.data.type);
                            $('input[name=drug_id]').val(data.data.drug_id);
                            $('input[name=drug_no]').val(data.data.drug_no);
                            $('input[name=drug_size]').val(data.data.drug_size);
                            $('input[name=drug_unit]').val(data.data.drug_unit);
                        }else{
                            alert(data.msg);
                        }
                    })
                    .fail(function() {
                        console.log("error");
                    })
            });
        })

    </script>